"""
@File    :   get_data.py
@Time    :   2024/01/18 14:36:45
@Author  :   glx 
@Version :   1.0
@Contact :   18095542g@connect.polyu.hk
@Desc    :   turn data into test_data
"""

# here put the import lib
import json
import os
import numpy as np
import math
import pandas as pd

with open(r"data\pattern.json", "r") as f:
    pattern = json.load(f)


# def count_order_of_magnitude(num1, num2):
#     ratio = abs(num1 / num2)
#     order_of_magnitude = math.floor(math.log10(ratio))
#     return order_of_magnitude


def count_mode(num_list: pd.Series):
    """计算众数"""
    return float(num_list.mode().iloc[0])


def get_order(num_list: pd.Series):
    order_list = pd.Series([int(math.log10(abs(number))) for number in num_list])
    mode = count_mode(order_list)
    order = 2 - mode
    return order


def change_order(num_list: pd.Series, order: int):
    num_list = num_list * (10**order)
    return num_list


if __name__ == "__main__":
    with open(r"data\test_data\Freq_real.csv", "r") as f:
        data = f.readlines()
        data = [float(i) for i in data]
    data = pd.Series(data)
    order = get_order(data)
    data = change_order(data, order)
    print(data)
